import VueRouter from "vue-router";
import Vue from 'vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        meta: {
            title: '书室'
        },
        component: () => import("@/views/home/Home"),
    },
    {
        path: '/pdf',
        meta: {
            title: 'pdf预览'
        },
        component: () => import("@/views/preview/pdf/Pdf")
    },
    {
        path: '/md',
        meta: {
            title: 'markdown预览'
        },
        component: () => import("@/views/preview/markdown/Markdown")
    }
]

// eslint-disable-next-line no-undef
const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    let title = to.meta.title;
    if (title) {
        document.title = title;
    }

    next();
})

export default router
